﻿@model Tuple<List<deviceManage.Models.DeviceType>, deviceManage.Models.BuyContract>
@{
    ViewData["Title"] = "采购合同";
}

<style>
    .layui-form-label{
        width:110px;
    }
    .layui-layout-body {
        overflow: auto;
    }
    .layui-fluid{
        padding-bottom:85px;
    }
</style>

 
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md8">
                    <form class="layui-form" action="doCreate" lay-filter="saveForm">
                        <input type="hidden" name="id" id="id" value="@Model.Item2.Id" />
                        <div class="layui-card">
                            <div class="layui-card-header">设备类型</div>
                            <div class="layui-card-body" style="padding: 15px;">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">设备类型</label>
                                        <div class="layui-input-inline">
                                            <select name="deviceTypeId" disabled="disabled">
                                                @foreach (var x in Model.Item1)
                                                {
                                                    @if (x.Id.Equals(Model.Item2.DeviceTypeId))
                                                    {
                                                        <option selected value="@x.Id">@x.Name</option>
                                                    }
                                                    else
                                                    {
                                                        <option value="@x.Id">@x.Name</option>
                                                    }

                                                }
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-card">
                            <div class="layui-card-header">合同内容</div>
                            <div class="layui-card-body" style="padding: 15px;">

                                <div class="layui-form-item">
                                    <div class="layui-block">
                                        <label class="layui-form-label">采购主题</label>
                                        <div class="layui-input-inline" style="width:400px;">
                                            <input type="text" name="title" readonly value="@Model.Item2.Title" lay-verify="required" autocomplete="off" class="layui-input" maxlength="100">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">采购员</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="BuyUser" readonly value="@Model.Item2.BuyUser" lay-verify="required" autocomplete="off" class="layui-input" maxlength="80">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">采购数量</label>
                                        <div class="layui-input-inline">
                                            <input type="number" name="BuyCount" readonly value="@Model.Item2.BuyCount" lay-verify="required" autocomplete="off" class="layui-input" maxlength="80">
                                        </div>
                                    </div>

                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">合同时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly="readonly" value="@if(Model.Item2.StartDate != null){@Model.Item2.StartDate.ToString().Substring(0, 10);} " name="StartDate" id="StartDate" lay-verify="required" autocomplete="off" class="layui-input date">

                                        </div>

                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label">到期时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly="readonly" value="@if(Model.Item2.EndDate != null){@Model.Item2.EndDate.ToString().Substring(0, 10);}" name="EndDate" id="EndDate" lay-verify="required" autocomplete="off" class="layui-input date">
                                        </div>
                                    </div>

                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">合同总费用(元）</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly style="text-align:right;padding-right:5px;" name="amount" value="@Model.Item2.Amount" lay-verify="money" autocomplete="off" class="layui-input" maxlength="20">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-block">
                                        <label class="layui-form-label">交货地点</label>
                                        <div class="layui-input-inline"style="width:400px;">
                                            <input type="text" name="Addr" readonly value="@Model.Item2.Addr" lay-verify="required" autocomplete="off" class="layui-input" maxlength="100">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-block">
                                        <label class="layui-form-label">设备用途</label>
                                        <div class="layui-input-inline"style="width:400px;">
                                            <textarea readonly style="height:80px;" name="Purpose" class="layui-textarea" maxlength="200">@Model.Item2.Purpose</textarea>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
 
                         

                    </form>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            合同附件
                          
                        </div>
                        <div class="layui-card-body" style="padding: 15px;">
                            <table class="layui-table layuiadmin-page-table" id="filesTable" lay-skin="line"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
  
<script>

 


    form.render(null, 'saveForm');
  


    /* 自定义验证规则 */
    form.verify({
        money: [/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/, '金额格式不正确']
    });



    //加载table
    var tableObj = table.render({
        elem: '#filesTable'
        ,height:"615px"
        , url: '/doc/getAllByObjectId?id=@Model.Item2.Id'
        , cols: [[
            { field: 'name', title: '文件名称',  templet: '<div><a class="fileLink" href="/doc/download?id={{d.id}}">{{ d.name}}</a></div>' }
     
        ]]
        , skin: 'line'
    });


    /* 监听提交 */
    form.on('submit(save)', function (data) {
        //开始保存合同信息
        $.post("/buyContract/save", data.field,
            function (e) {
               layer.msg(e.msg);
                if (e.code == 1) { //保存成功
                    window.parent.tableObj.reload();
                    window.parent.layer.closeAll();
                }
            });
            return false;
    });


    

</script>
